#include "drawable.h"

Drawable::Drawable(RenderData render_data)
	: render_data {render_data}
{}

Drawable::Drawable(RenderData render_data, Sprite sprite)
	: Drawable(render_data)
{
	this->register_sprite(sprite);
}

void Drawable::update(State& state, bool pressed_keys[], int& camera_x, int& camera_y)
{}

void Drawable::render(SDL_Renderer *renderer)
{
	if (!render_data.on_screen || render_data.texture == nullptr)
		return;

	Sprite& s = multi_sprite.selected();
	if (s.animated) {
		s.src.x = s.animation_x_offset + s.src.w * (s.current_frame / s.duration);
		s.current_frame = (s.current_frame + 1) % (s.frames * s.duration);
	}

	SDL_RenderCopy(renderer, render_data.texture, &s.src.rect, &render_data.dst.rect);
}

inline void Drawable::register_sprite(Sprite sprite)
{
	multi_sprite.sprites.push_back(sprite);
}

inline void Drawable::scale(int w, int h)
{
	render_data.dst.scale(w, h);
}

inline void Drawable::scale(float f)
{
	render_data.dst.scale(f);
}